export const Text = {
    NOTICE_TIPS: '公告内容不能为空',
    MAGIC_TIPS: '请添加图片',
    RICH_TIPS: '请上传图片',
    ENTER_TIPS: '请填写文案内容',
    IMAGE_TEXT_NAV_TIPS: '请添加图片',
    IMAGE_TEXT_AD_TIPS: '请选择一个广告',
    GROUP_TIPS: ''
}

export const resetItems = function (data) {
    data.forEach(function (item, idx) {
        item.active = false;
    })
}
//校验方法
export const checkItems = function (data) {
    var _flag = false;
    var _text = ""
    for (var i = 0; i < data.length; i++) {
        //商品
        if (data[i].type == "GOODS") {
            if (data[i].goodsSource == 1) {
                if (data[i].goods == 0) {
                    _flag = true;
                    resetItems(data);
                    data[i].active = true;
                    _text = '商品不能为空';
                    break;
                }
            } else if (data[i].goodsSource == 2) {
                if (!data[i].goodsgroupId) {
                    _flag = true;
                    resetItems(data);
                    data[i].active = true;
                    _text = '请选择商品分组';
                    break;
                } else {
                    if (!data[i].showNum.length) {
                        _flag = true;
                        resetItems(data);
                        data[i].active = true;
                        _text = '显示个数不能为空';
                        break;
                    }
                }

            }
        }
        //商品分组
        if (data[i].type == "GROUP") {
            if (data[i].menuList.length == 0) {
                _flag = true;
                resetItems(data);
                data[i].active = true;
                _text = '请选择商品分组';
                break;
            } else {
                for (var j = 0; j < data[i].menuList.length; j++) {
                    if (data[i].menuList[j].showType == 1 && !data[i].menuList[j].showNum) {
                        _flag = true;
                        resetItems(data);
                        data[i].active = true;
                        _text = data[i].menuList[j].groupName + '分组显示个数不能为空';
                        break;
                    }
                }
            }

        }
        //图文广告
        if (data[i].type == "IMAGE_TEXT_AD") {
            if (data[i].navList.length == 0) {
                _flag = true;
                resetItems(data);
                data[i].active = true;
                _text = Text.IMAGE_TEXT_AD_TIPS;
                break;
            } else {
                for (var j = 0; j < data[i].navList.length; j++) {
                    if (data[i].navList[j].img.length == 0) {
                        _flag = true;
                        resetItems(data);
                        data[i].active = true;
                        _text = Text.IMAGE_TEXT_AD_TIPS;
                        break;
                    }
                }
            }

        }
        //图文导航
        if (data[i].type == "IMAGE_TEXT_NAV") {
            if (data[i].navList.length == 0) {
                _flag = true;
                resetItems(data);
                data[i].active = true;
                _text = '请添加图文导航';
                break;
            } else if (data[i].navList.length < 4) {
                _flag = true;
                resetItems(data);
                data[i].active = true;
                _text = '图文导航不能少于4个';
                break;
            } else {
                for (var j = 0; j < data[i].navList.length; j++) {
                    if (data[i].navList[j].img.length == 0) {
                        _flag = true;
                        resetItems(data);
                        data[i].active = true;
                        _text = Text.IMAGE_TEXT_NAV_TIPS;
                        break;
                    }
                }
            }

        }
        //进入店铺
        if (data[i].type == "ENTER_SHOP") {
            if (data[i].text.length == 0) {
                _flag = true;
                resetItems(data);
                data[i].active = true;
                _text = Text.ENTER_TIPS;
                break;
            }
        }
        //富文本
        if (data[i].type == "RICH_EDIT") {
            if (data[i].imageUrl.length == 0) {
                _flag = true;
                resetItems(data);
                data[i].active = true;
                _text = Text.RICH_TIPS;
                break;
            }
        }
        //公告
        if (data[i].type == "NOTICE") {
            if (data[i].text.length == 0) {
                _flag = true;
                resetItems(data);
                data[i].active = true;
                _text = Text.NOTICE_TIPS;
                break;
            }
        }
        //魔方
        if (data[i].type == "MAGIC_CUBE") {
            for (var j = 0; j < data[i].imgMsgList.length; j++) {
                if (data[i].imgMsgList[j].img.length == 0) {
                    _flag = true;
                    resetItems(data);
                    data[i].active = true;
                    _text = Text.MAGIC_TIPS;
                    break;
                }
            }
        }
        //限时折扣
        if (data[i].type == "DISCOUNT") {
            if (data[i].discountContent.activityName.trim().length == 0) {
                _flag = true;
                resetItems(data);
                data[i].active = true;
                _text = '限时活动不能为空';
                break;
            } else {
                if (data[i].discountContent.showNum.trim().length == 0) {
                    _flag = true;
                    resetItems(data);
                    data[i].active = true;
                    _text = '限时活动显示商品数不能为空';
                    break;
                }
            }
        }
        //优惠券
        if (data[i].type == "DISCOUNT_COUPON") {
            if (data[i].discount.length == 0) {
                _flag = true;
                resetItems(data);
                data[i].active = true;
                _text = '优惠券不能为空';
                break;
            }
        }
    }

    return {
        flag: _flag,
        text: _text
    }
}
